<template>
	<div class="clear_box">
		<h1>新增职业</h1>
		<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="名称" prop="name" class="name1">
				<el-input v-model.number="ruleForm.name"></el-input>
			</el-form-item>
			<el-form-item label="标签" prop="biaoqian" class="name1">
				<el-input v-model.number="ruleForm.biaoqian"></el-input>
			</el-form-item>
			</br>
			<el-form-item label="薪资" prop="money" class="name1">
				<el-input v-model.number="ruleForm.money"></el-input>
			</el-form-item>
			<el-form-item label="人数" prop="peaple" class="name1">
				<el-input v-model.number="ruleForm.peaple"></el-input>
			</el-form-item>
			</br>

			<el-form-item label="学历" prop="education" class="name1">
				<el-input v-model.number="ruleForm.education"></el-input>
			</el-form-item>
			<el-form-item label="经验" prop="experience" class="name1">
				<el-input v-model.number="ruleForm.experience"></el-input>
			</el-form-item>
			</br>
			<el-form-item label="地址" prop="adress" class="name1">
				<el-input v-model.number="ruleForm.adress"></el-input>
			</el-form-item>
			<el-form-item label="联系方式" prop="lianxi" class="name1">
				<el-input v-model.number="ruleForm.lianxi"></el-input>
			</el-form-item>
			<el-form-item label="职业描述" prop="atextarea"  class="atextarea">
				<el-input type="textarea" :rows="15" placeholder="请输入内容" v-model.number="ruleForm.atextarea">
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
				<el-button @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
		import config from '@/assets/js/config.js'
		import axios from "axios"
	export default {
		data() {
			var checkName = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('名称不能为空'));
				}
			};
			var checkBiaoqian = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('标签不能为空'));
				}
			};
			var checkMoney = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('薪资不能为空'));
				}
			};
			var checkPeaple = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写人数'));
				}
			};
			var checkEducation = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写学历'));
				}
			};
			var checkExperience = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写经验'));
				}
			};
			var checkAdress = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写地址'));
				}
			};
			var checkLianxi = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写联系方式'));
				}
			};
			var checkAtextarea = (rule, value, callback) => {
				if(!value) {
					return callback(new Error('请填写职业介绍'));
				}
			};
			return {
				ruleForm: {
					name: '',
					biaoqian: "",
					money: "",
					peaple: "",
					education: "",
					experience: "",
					adress: "",
					lianxi: "",
					atextarea:''
				},
				
				list:"",
				
				rules: {
					name: [{
						validator: checkName,
						trigger: 'blur'
					}],
					biaoqian: [{
						validator: checkBiaoqian,
						trigger: 'blur'
					}],
					money: [{
						validator: checkMoney,
						trigger: 'blur'
					}],
					peaple: [{
						validator: checkPeaple,
						trigger: 'blur'
					}],
					education: [{
						validator: checkEducation,
						trigger: 'blur'
					}],
					experience: [{
						validator: checkExperience,
						trigger: 'blur'
					}],
					adress: [{
						validator: checkAdress,
						trigger: 'blur'
					}],
					lianxi: [{
						validator: checkLianxi,
						trigger: 'blur'
					}],
					atextarea: [{
					validator: checkAtextarea,
						trigger: 'blur'
					}],
				}
			};
		},
		
		
	    mounted(){
	    	console.log(this.ruleForm.name)
	    },
		methods:{
			submitForm(formName){
				this.$refs[formName].validate((valid) => {
					if(valid) {
						alert('submit!');
					} else {
						console.log('error submit!!');
						return false;
					}
				});				
			//添加
			console.log(this.$store.state.token);
			 this.list=this.ruleForm;
			 console.log(this.ruleForm)
			 console.log("招聘",this.list);
			 var baseUrl = 'http://yaochiwan2.bluej.cn';
                axios.post(baseUrl + '/jobs/add',{
               	address: this.ruleForm.adress,
				contact: this.ruleForm.lianxi,
				education:this.ruleForm.education,
				experience: this.ruleForm.experience,
				format_describe: this.ruleForm.atextarea,
				name: this.ruleForm.name,
				people: this.ruleForm.peaple,
				price: this.ruleForm.money,
				property_string:this.ruleForm.biaoqian		
               },{
               	headers: {
					  Authorization: "Bearer " + this.$store.state.token
					 }
               }).then((res) => {
               	console.log("渲染")
//					console.log(res);	
				this.$router.push({
			 	name:"recruit"		
			 })
			});		 
		},
			resetForm(formName){
				this.$refs[formName].resetFields();				
			}
		}
	}
</script>

<style lang="scss" scoped="scoped">
	.clear_box {
		width: 100%;
		.demo-ruleForm {
			width: 100%;
			.name1 {
				width: 25%;
				display: inline-block!important;
			}
		}
		.atextarea{
			width:50%
		}
	}
</style>